package com.wyc.serviceorder.controller;

import com.wyc.internalCommon.request.OrderInfo;
import com.wyc.internalCommon.result.ApiResult;
import com.wyc.serviceorder.dto.OrderDTO;
import com.wyc.serviceorder.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author li
 * @since 2023-04-02
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    @RequestMapping("/list")
    public ApiResult queryPage(){
        return ApiResult.success();
    }

    /**
     * 添加订单
     * @param orderInfo
     * @return
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody OrderInfo orderInfo, HttpServletRequest request){
//        // 获取请i去头中设备唯一码
//        String deviceCode = request.getHeader("deviceCode");
//        order.setDeviceCode(deviceCode);

        return orderService.add(orderInfo);
    }

    /**
     * 司机出发去接乘客
     * @param orderInfo
     * @return
     */
    @PostMapping("/to-pick-up-passenger")
    public ApiResult toPickUpPassenger(@RequestBody OrderInfo orderInfo){
        return orderService.toPickUpPassenger(orderInfo);
    }

    /**
     * 司机到达上车地点
     * @param id
     * @return
     */
    @GetMapping("/driver-arrived-departure")
    public ApiResult driverArrivedDeparture(@RequestParam Long id){
        return orderService.driverArrivedDeparture(id);
    }

    /**
     * 司机接到乘客
     * @param orderInfo
     * @return
     */
    @PostMapping("/pick-up-passenger")
    public ApiResult pickUpPassenger(@RequestBody OrderInfo orderInfo){
        return orderService.pickUpPassenger(orderInfo);
    }

    /**
     * 乘客下车，行程结束
     * @param orderInfo
     * @return
     */
    @PostMapping("/passenger-getoff")
    public ApiResult passengerGetoff(@RequestBody OrderInfo orderInfo){
        return orderService.passengerGetoff(orderInfo);
    }

    /**
     * 支付完成
     * @param orderId
     */
    @PostMapping("/pay")
    public void pay(@RequestParam("orderId") Long orderId){
        orderService.pay(orderId);
    }

    /**
     * 取消订单
     * @param orderId
     * @param identity 取消人的身份标识（1.乘客 2.司机3.平台）
     * @return
     */
    @PostMapping("/cancel")
    public ApiResult cancelOrder(@RequestParam("orderId") Long orderId, @RequestParam("identity") String identity){
       return orderService.cancelOrder(orderId,identity);
    }

}
